﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;

namespace OA.DAL
{
    public class Dictionary : Base<Model.Dictionary>
    {
        public Dictionary(ISession isession)
            : base(isession)
        {

        }

        /// <summary>
        /// 获取字典
        /// </summary>
        /// <param name="Code">字典编号</param>
        /// <returns></returns>
        public Model.Dictionary GetDictionary(string Code)
        {
            Model.Dictionary ret = null;
            var list = Get("Code=? and Type=1",null,Code);
            if (list.Count > 0) ret = list[0];
            return ret;
        }
        /// <summary>
        /// 获取数据字典
        /// </summary>
        /// <param name="parentID">上级ID</param>
        /// <param name="Code">字典编号</param>
        /// <returns></returns>
        public Model.Dictionary GetData(int parentID, string Code)
        {
            Model.Dictionary ret = null;
            var list = Get("ParentID=? and Code=? and Type=2", null,parentID, Code);
            if (list.Count > 0) ret = list[0];
            return ret;
        }

        /// <summary>
        /// 获取字典下级的数据
        /// </summary>
        /// <param name="Code"></param>
        /// <returns></returns>
        public IList<Model.Dictionary> GetChilds(string Code)
        {
            return Get("Parent.Code=? and Type=2", null,Code);
        }
    }
}
